<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/1/4 0004
 * Time: 11:32
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);


namespace app\common\business;

use app\common\model\MallMembercard as ModelObj;
use app\common\validate\Membercard as ValObj;
use think\Exception;

class Membercard extends Base
{
    /**
     * @var ValObj
     */
    protected ValObj $valObj;
    /**
     * @var ModelObj
     */
    protected ModelObj $modelObj;

    /**
     *
     */
    public function __construct()
    {
        $this->valObj = new ValObj();
        $this->modelObj = new ModelObj();
    }

    /**
     *  获取指定会员卡信息
     * @param $id
     * @return array|\think\Model|null
     * @throws Exception
     */
    public function getMembercardInfo($id){

        try{
            $info =$this->modelObj->getModelByInfo([['id','=',$id]],'*');
        }catch (\Exception $e){
            throw new Exception("查询失败");
        }
        return $info;
    }

    /**
     * 获取全部的会员卡
     * @return array
     * @throws Exception
     */
    public function getMembercardlist(){
        try{
            $lists =$this->modelObj->getModelByListToArray([['status','=',1]],'id,title,price,quanyi,userrule,remark');
        }catch (\Exception $e){
            throw new Exception("查询失败");
        }

        return $lists;
    }
}